import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule, Http, BrowserXhr } from '@angular/http';
import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
import { NgProgressModule, NgProgressBrowserXhr } from 'ngx-progressbar';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import { LocalStorage } from 'app/ptpmc/localstorage/local.storage';
import { UserService } from 'app/ptpmc/comm/user.service';
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { JWTInterceptor } from 'app/ptpmc/interceptor/jwt-interceptor';
import { ResponseInterceptor } from 'app/ptpmc/interceptor/response-interceptor';
import { AuthGuard } from 'app/ptpmc/guard/auth.guard';
import { CommService } from './ptpmc/comm/comm.service';
import { RouteReuseStrategy } from '@angular/router';
import { SimpleReuseStrategy } from './ptpmc/components/multytab/multi-tab';

export function HttpLoaderFactory(http: Http) {
    return new TranslateHttpLoader(http, '/assets/i18n/', '.json');
}

@NgModule({
    declarations: [
        AppComponent
    ],
    imports: [
        BrowserModule,
        FormsModule,
        HttpModule, NgProgressModule,
        HttpClientModule,
        TranslateModule.forRoot({
            loader: {
                provide: TranslateLoader,
                useFactory: HttpLoaderFactory,
                deps: [Http]
            }
        }),
        AppRoutingModule
    ],
    providers: [
        { provide: RouteReuseStrategy, useClass: SimpleReuseStrategy },
        { provide: BrowserXhr, useClass: NgProgressBrowserXhr },
        {
            provide: HTTP_INTERCEPTORS,
            useClass: JWTInterceptor,
            multi: true
        },
        {
            provide: HTTP_INTERCEPTORS,
            useClass: ResponseInterceptor,
            multi: true
        },
        CommService, LocalStorage, UserService, AuthGuard
    ],
    bootstrap: [AppComponent]
})
export class AppModule { }
